package com.fz.controller;

import com.fz.entity.Product;
import com.fz.mapper.AdminHproductMapper;
import com.fz.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Z-C-Y on 2018-03-07.
 * 艺术家管理表
 */
@Controller
public class AdminHproductController {
    @Autowired
    protected AdminHproductMapper adminHproductMapper;

    @RequestMapping("/admin/Hproduct")
    public String Hproduct(Model model, HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*实现分页并查询的功能*/
        int  pageNun1 = 1;
        if((req.getParameter("pageNun") != null) && !("".equals(req.getParameter("pageNun")))){
            pageNun1 = Integer.parseInt(req.getParameter("pageNun"));
        }
        //System.out.println("==获得当前是第几页==pageNun===="+req.getParameter("pageNun"));
        //每页显示的记录数
        int pageSize = 10;
        /*分页======查询数据库的数据的总数据*/
        List<Product> list4 = adminHproductMapper.queryProduct();
        model.addAttribute("list4Product",list4);

        /*得到表中总条数*/
        int totalRecord = list4.size();

        //有了初始化数据，就可以创建PageBean对象了
        PageBean pbm = new PageBean(pageNun1, pageSize, totalRecord);

        model.addAttribute("pbm",pbm);
        //获取PageBeanManage对象中的startIndex;
        int startIndex = pbm.getStartIndex();

        //有了pageSize和startIndex，就可以拿到每页的数据
        List<Product> listProduct =  adminHproductMapper.queryProductData(startIndex,pageSize);
        model.addAttribute("listProduct",listProduct);

        return "forward:/admin/hproduct.jsp";
    }
   // public String



}
